import { createApp } from 'vue'
import App from './App.vue'

import store, { key } from './store'

// // 路由
import router from './router'
import { setupRouterGuard } from '@/router/router'

import { initAppConfigStore } from '@/logics/initAppConfig'

// 注册全局svg图标组件
import svgIcon from '@/components/SvgIcon/index.vue'
import 'virtual:svg-icons-register'

import '@/styles/gm/index.scss'
import '@/styles/element/components'

import { setupI18n } from '@/locales/setupI18n'

import VueNativeSock from 'vue-native-websocket-vue3'
import {
  SOCKET_ONOPEN,
  SOCKET_ONCLOSE,
  SOCKET_ONERROR,
  SOCKET_ONMESSAGE,
  SOCKET_RECONNECT,
  SOCKET_RECONNECT_ERROR
} from "@/settings/mutation-types"
const mutations = {
  SOCKET_ONOPEN,
  SOCKET_ONCLOSE,
  SOCKET_ONERROR,
  SOCKET_ONMESSAGE,
  SOCKET_RECONNECT,
  SOCKET_RECONNECT_ERROR
}

async function bootstrap() {
  const app = createApp(App)
  app.component('svg-icon', svgIcon)
  app.use(store, key)
  app.use(router)
  setupRouterGuard(router)
  initAppConfigStore()
  // Multilingual configuration
  // Asynchronous case: language files may be obtained from the server side
  await setupI18n(app)

  app.mount('#app')

  app.use(VueNativeSock, `${import.meta.env.VITE_NOTIFICATION_WEB_SOCKET}?userID=${localStorage.getItem("userID")}`, {
    store: store,
    mutations: mutations,
    // 数据发送/接收使用使用json
    format: "json",
    // 开启手动调用 connect() 连接服务器
    connectManually: true,
    // 开启自动重连
    reconnection: true,
    // 尝试重连的次数
    reconnectionAttempts: 5,
    // 重连间隔时间
    reconnectionDelay: 3000

  })

  return app
}

const app =  bootstrap()
export default app
